/*
 * Copyright (C) 2016 Zhejiang LISHI Technology CO.,LTD.
 * All rights reserved.
 * Official Web Site: http://www.lishiots.com.
 * Developer Web Site: http://open.lishiots.com.
 */
package com.drore.cloud.sdkjdbc.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Objects;

/***
 * LogbackLogger
 * @since:cloud-sdk 1.0 
 * @author <a href="mailto:xiaoymin@foxmail.com">xiaoymin@foxmail.com</a> 
 * 2016年7月3日 上午12:28:00
 */
public class LogbackLogger {
	
	/***
	 * 记录打印日志
	 * @param msg
	 *
	 */
	public static void info(Object msg){
		Logger logger=null;
		StackTraceElement[] ste=Thread.currentThread().getStackTrace();
		if (ste!=null&&ste.length>3){
			logger=LoggerFactory.getLogger(ste[2].getClassName());
		}else{
			logger=LoggerFactory.getLogger(Thread.currentThread().getClass());
		}
		logger.info(Objects.toString(msg, ""));
	}
	
	public static void error(Object e){
		Logger logger=LoggerFactory.getLogger(Thread.currentThread().getClass());
		StringWriter out = new StringWriter();
		if(e instanceof Throwable){
			Throwable ef=(Throwable)e;
			ef.printStackTrace(new PrintWriter(out));
			logger.error(out.toString());
		}else {
			logger.error(Objects.toString(e));
		}
	}


	public static void main(String[] args) {
		LogbackLogger.info("info日志。。。");
		new Thread(new Runnable() {
			@Override
			public void run() {
				LogbackLogger.info("info日志ffffffffffff。。。");
			}
		}).start();

		LogbackLogger.error(new Exception("异常信息..."));
	}

}